from datetime import datetime

from sqlalchemy import Boolean, DateTime, func, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Mapped, mapped_column

Base = declarative_base()


class BasicModel(Base):
    """
    基本数据库模型
    """
    __abstract__ = True

    id: Mapped[int] = mapped_column(Integer, primary_key=True, nullable=False, autoincrement=True, comment='主键 ID')
    """
    主键 ID
    整形，自增
    """
    created_at: Mapped[datetime] = mapped_column(
        DateTime, index=True, nullable=False, default=func.now(), comment='创建时间'
    )
    """
    创建时间
    默认值自动取当前时间
    """
    modified_at: Mapped[datetime] = mapped_column(
        DateTime, index=True, nullable=False, default=func.now(), comment='修改时间'
    )
    """
    修改时间
    默认值自动取当前时间
    """
    is_deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, comment='逻辑删除')
    """
    逻辑删除
    """


def create_tables(engine):
    Base.metadata.create_all(engine)
